import testApi from '@/api/testApi'
import { required } from '@/utils/formRules'
const formData = ref({})

const formRules = ref({
	<%_ for(var i = 0; i < formConfig.fields.length; i++){ _%>
		<%_ if(formConfig.fields[i].required){ _%>
		<%= formConfig.fields[i].name %>: [required('<%= ['select', 'radio', 'checkbox','date','dateRange','cascader','any'].includes(formConfig.fields[i].type) ? '请选择' : formConfig.fields[i].type === 'file' ? '请上传' : '请输入' %><%= formConfig.fields[i].label %>')],
		<%_ } _%>
	<%_ } _%>
})

const submitLoading = ref(false)
const formRef = ref()

const onSubmit =  () => {
  formRef.value.validate().then(async () => {
    try {
      submitLoading.value = true
      await testApi.submit(formData.value)
      // onClose()
      // emit('successful')
    } catch (error) {
      console.log(error)
    } finally {
      submitLoading.value = false
    }
  })
}